package com.settlement.system.model.entity.common;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.alibaba.excel.enums.BooleanEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.annotation.AdmitCustomizedExpore;
import com.settlement.system.common.enums.CostAllocationEnum;
import com.settlement.system.converter.*;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 统一账单明细
 *
 * @author Ximi
 * @since 2020-07-01
 */
@AdmitCustomizedExpore(name = "RR-统一账单明细")
@Data
@ExcelIgnoreUnannotated
@HeadStyle(fillBackgroundColor = 9, fillForegroundColor = 9,wrapped = BooleanEnum.FALSE)
@HeadRowHeight(value = 20)
@HeadFontStyle(fontHeightInPoints = 11)
public class TblUnificationBillDetail extends BaseModel implements Serializable {

    /**
     * 原始账单ID
     */
    @ExcelProperty(value = "原始账单ID",converter = BigNumberFormatConvert.class)
    @ApiModelProperty(value = "原始账单ID", required = true)
    @NotBlank(message = "原始账单ID不能为空")
    private String originBillId;

    /**
     * 统一账单ID
     */
    @ExcelProperty(value = "统一账单ID",index = 0)
    @ApiModelProperty(value = "统一账单ID", required = true)
    @NotBlank(message = "统一账单ID不能为空")
    private String unificationBillId;

    /**
     * 统一账单汇总ID
     */
    @ExcelProperty(value = "汇总ID",converter = BigNumberFormatConvert.class)
    @ApiModelProperty(value = "汇总ID")
    private String summaryId;

    /**
     *
     */
    @ExcelProperty(value = "渠道编码")
    @ApiModelProperty(value = "渠道编码")
    @NotBlank(message = "渠道编码不能为空")
    private String channelNo;

    /**
     * 渠道
     */
    @ExcelProperty(value = "渠道")
    @ApiModelProperty(value = "渠道", required = true)
    @NotBlank(message = "渠道不能为空")
    private String channelName;

    /**
     * 账单类型
     */
    @ExcelProperty(value = "账单类型")
    @ApiModelProperty(value = "账单类型", required = true)
    @NotBlank(message = "账单类型不能为空")
    private String billType;

    private String billTypeNo;

    /**
     * 零售店铺编码
     */
    @ExcelProperty(value = "零售店铺编码")
    @ApiModelProperty(value = "零售店铺编码")
    private String shopNo;

    /**
     * 店铺名称
     */
    @ExcelProperty(value = "零售店铺名称")
    @ApiModelProperty(value = "零售店铺名称")
    private String shopName;

    /**
     * 日期
     */
    @ExcelProperty(value = "日期",converter = DateFormatConvert.class)
    @ApiModelProperty(value = "日期")
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    private Date outDate;

    /**
     * 外部订单号
     */
    @ExcelProperty(value = "外部订单号",converter = BigNumberFormatConvert.class)
    @ApiModelProperty(value = "外部订单号")
    private String thirdOrderNo;

    /**
     * 原始账单项目
     */
    @ExcelProperty(value = "原始账单项目")
    @ApiModelProperty(value = "原始账单项目")
    private String originBillProject;

    /**
     * 记账项目
     */
    @ExcelProperty(value = "记账项目")
    @ApiModelProperty(value = "记账项目")
    private String recordAccountProject;

    /**
     * 账单金额
     */
    @ExcelProperty(value = "账单金额")
    @ApiModelProperty(value = "账单金额", required = true)
    @NotNull(message = "账单金额不能为空")
    private BigDecimal billAmount;

    /**
     * 状态
     */
    @ExcelProperty(value = "状态",converter = UnificationStatusConvert.class)
    @ApiModelProperty(value = "状态,NM:未匹配,CM:完成匹配,", required = true)
    @NotBlank(message = "状态不能为空")
    private String status;

    /**
     * 稽核金额
     */
    @ApiModelProperty(value = "稽核金额")
    private BigDecimal auditAmount;

    /**
     * 交易流水号
     */
    @ExcelProperty(value = "交易流水号",converter = BigNumberFormatConvert.class)
    @ApiModelProperty(value = "交易流水号")
    private String serialNo;

    /**
     * 虚拟账户
     */
    @ApiModelProperty(value = "虚拟账户")
    private String virtualAccount;

    /**
     * 会计期间
     */
    @ExcelProperty(value = "会计期间")
    @ApiModelProperty(value = "会计期间")
    private String accountingPeriod;

    /**
     * 入账主体
     */
    @ExcelProperty(value = "入账主体")
    @ApiModelProperty(value = "入账主体")
    private String companyNo;

    /**
     * 凭证类型
     */
    @ExcelProperty(value = "凭证类型",converter = UnificationConvertVoucherType.class)
    @ApiModelProperty(value = "凭证类型")
    private String voucherType;

    @ColumnWidth(13)
    @ExcelProperty(value = "是否分摊")
    private String shareOrNotStr;

    @ColumnWidth(13)
    @ExcelProperty(value = "票前票后")
    private String beforeOrAfterTicketStr;

    /**
     * NC_渠道
     */
    @ApiModelProperty(value = "NC_辅助项_渠道")
    private String ncChannelName;

    /**
     * NC店铺编码
     */
    @ApiModelProperty(value = "NC_辅助项_店铺")
    private String ncShopNo;

    /**
     * NC_店铺
     */
    @ApiModelProperty(value = "NC_店铺名称")
    private String ncShopName;

    /**
     * 供应商名称
     */
    @ExcelProperty(value = "供应商名称")
    @ApiModelProperty(value = "供应商名称")
    private String supplierName;

    /**
     * NC_供应商档案
     */
    @ApiModelProperty(value = "NC_辅助项_供应商档案")
    private String ncSupplierRecord;

    /**
     * NC_客户档案
     */
    @ApiModelProperty(value = "NC_辅助项_客户档案")
    private String ncCustomerRecord;

    /**
     * NC_虚拟账户
     */
    @ApiModelProperty(value = "NC_辅助项_虚拟账户")
    private String ncVirtualAccount;

    /**
     * NC_部门编码
     */
    @ApiModelProperty(value = "NC_辅助项_部门")
    private String ncDeptNo;

    /**
     * NC_收费项目
     */
    @ApiModelProperty(value = "NC_辅助项_收费项目")
    private String ncChargeProject;

    /**
     * 稽核标识
     */
    @ExcelProperty(value = "稽核标识")
    @ApiModelProperty(value = "稽核标识")
    private String auditMark;

    /**
     * 是否参与记账
     */
    @ExcelProperty(value = "是否参与记账")
    @ApiModelProperty(value = "是否参与记账")
    private String isJoinRecordAccount;

    /**
     * 是否资金账户数据
     */
    @ApiModelProperty(value = "是否资金账户数据")
    private String isCapitalAccountData;

    /**
     * 活动ID
     */
    @ApiModelProperty(value = "活动ID")
    private String actionId;

    /**
     * 爱库存_档期名称
     */
    @ApiModelProperty(value = "爱库存_档期名称")
    private String akcCalendarName;

    /**
     * 爱库存_主档期名称
     */
    @ApiModelProperty(value = "爱库存_主档期名称")
    private String akcMasterCalendarName;

    /**
     * 爱库存_数量
     */
    @ApiModelProperty(value = "爱库存_数量")
    private Integer akcQty;

    /**
     * 爱库存_售后服务单_AD单号
     */
    @ApiModelProperty(value = "爱库存_售后服务单_AD单号")
    private String akcAfterSaleNo;

    /**
     * 登陆账号
     */
    @ApiModelProperty(value = "登陆账号")
    private String loginAccount;

    /**
     * 店铺账号
     */
    @ExcelProperty(value = "店铺账号")
    @ApiModelProperty(value = "店铺账号")
    private String shopAccount;

    /**
     * 爱库存_对账单类型
     */
    @ApiModelProperty(value = "爱库存_对账单类型")
    private String akcVerifyBillType;

    /**
     * 账号NC店铺名称/登陆账号名称
     */
    @ExcelProperty(value = "登陆账号名称")
    @ApiModelProperty(value = "账号NC店铺名称")
    private String accountNcShopName;

    /**
     * 问题描述
     */
    @ExcelProperty(value = "问题描述",converter = UnificationProblemDescConvert.class)
    @ApiModelProperty(value = "问题描述")
    private Integer problemDesc;

    /**
     * 实际关账日期
     */
    private Date realCloseAccountDate;

    /**
     * 订单三级来源编码
     */
    private String threeLevelChannelNo;

    /**
     * 线下打款更新店铺对应的渠道
     */
    @ExcelProperty(value = "更新后店铺渠道")
    private String shopOfChannelName;

    /**
     * 线下打款更新店铺对应的入账主体
     */
    @ExcelProperty(value = "更新后入账主体")
    private String shopOfNcEnterAccountBody;


    private int total;


    /**
     * 创建时间
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "创建时间",converter = DateTimeFormatConvert.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date createTime;

    /**
     * 创建人
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "创建人")
    public String createUser;

    /**
     * 更新时间
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "更新时间",converter = DateTimeFormatConvert.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date updateTime;

    /**
     * 更新人
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "更新人")
    public String updateUser;

    /**
     * 账单大类
     */
    @ColumnWidth(13)
    @ExcelProperty(value = "账单大类",converter = BillCategoryConvert.class)
    @ApiModelProperty(value = "账单大类（1、平台账单，2、营销工具，3、手工调账）")
    private String billCategory;

    /**
     * 是否分摊
     */
    @ApiModelProperty(value = "是否分摊(1,是,  0否)")
    private String shareOrNot;

    /**
     * 票前票后
     */

    @ApiModelProperty(value = "票前票后(1,票前,  2票后,  3不涉及)")
    private String beforeOrAfterTicket;

    public void setShareOrNot(String shareOrNot) {
        this.shareOrNot = shareOrNot;
        if(StringUtils.isNotEmpty(shareOrNot)){
            this.shareOrNotStr = shareOrNot.replace(CostAllocationEnum.ShareOrNotEnum.NO.getNo(), CostAllocationEnum.ShareOrNotEnum.NO.getName())
                    .replace(CostAllocationEnum.ShareOrNotEnum.YES.getNo(), CostAllocationEnum.ShareOrNotEnum.YES.getName());
        }
    }

    public void setBeforeOrAfterTicket(String beforeOrAfterTicket) {
        this.beforeOrAfterTicket = beforeOrAfterTicket;
        if(StringUtils.isNotEmpty(beforeOrAfterTicket)){
            this.beforeOrAfterTicketStr = beforeOrAfterTicket
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.AFTER.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.BEFORE.getName())
                    .replace(CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getNo(), CostAllocationEnum.BeforeOrAfterTicketEnum.NOT_INVOLVE.getName());
        }
    }
}
